﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Gmis.IDAL;
using Gmis.DBUtility;
namespace Gmis.SqlServerDAL
{
    /// <summary>
    /// 数据访问类:PMember
    /// </summary>
    public partial class PMember : IPMember
    {
        public PMember()
        { }
        #region  Method

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string sId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from PMember");
            strSql.Append(" where sId=@sId ");
            SqlParameter[] parameters = {
					new SqlParameter("@sId", SqlDbType.VarChar,50)};
            parameters[0].Value = sId;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Gmis.Model.PMember model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into PMember(");
            strSql.Append("sId,sNumber,sName,sSex,dBorn,sMarry,sIdentity,sNation,sEducation,sWork,sWorkPlace,sPosition,nAge,sNative,dJoin,sMobile,sAddress,sPicture,sCharge,sComment,iPicture,dInDate,sInReason,sInPlace,dOutDate,sOutReason,sOutPlace)");
            strSql.Append(" values (");
            strSql.Append("@sId,@sNumber,@sName,@sSex,@dBorn,@sMarry,@sIdentity,@sNation,@sEducation,@sWork,@sWorkPlace,@sPosition,@nAge,@sNative,@dJoin,@sMobile,@sAddress,@sPicture,@sCharge,@sComment,@iPicture,@dInDate,@sInReason,@sInPlace,@dOutDate,@sOutReason,@sOutPlace)");
            SqlParameter[] parameters = {
					new SqlParameter("@sId", SqlDbType.VarChar,50),
					new SqlParameter("@sNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@sName", SqlDbType.NVarChar,50),
					new SqlParameter("@sSex", SqlDbType.Char,4),
					new SqlParameter("@dBorn", SqlDbType.DateTime),
					new SqlParameter("@sMarry", SqlDbType.NVarChar,50),
					new SqlParameter("@sIdentity", SqlDbType.NVarChar,50),
					new SqlParameter("@sNation", SqlDbType.NVarChar,50),
					new SqlParameter("@sEducation", SqlDbType.NVarChar,50),
					new SqlParameter("@sWork", SqlDbType.NVarChar,50),
					new SqlParameter("@sWorkPlace", SqlDbType.NVarChar,50),
					new SqlParameter("@sPosition", SqlDbType.NVarChar,50),
					new SqlParameter("@nAge", SqlDbType.Int,4),
					new SqlParameter("@sNative", SqlDbType.NVarChar,200),
					new SqlParameter("@dJoin", SqlDbType.DateTime),
					new SqlParameter("@sMobile", SqlDbType.NVarChar,50),
					new SqlParameter("@sAddress", SqlDbType.NVarChar,100),
					new SqlParameter("@sPicture", SqlDbType.NVarChar,256),
					new SqlParameter("@sCharge", SqlDbType.NVarChar,50),
					new SqlParameter("@sComment", SqlDbType.NVarChar,300),
					new SqlParameter("@iPicture", SqlDbType.Image),
					new SqlParameter("@dInDate", SqlDbType.DateTime),
					new SqlParameter("@sInReason", SqlDbType.NVarChar,128),
					new SqlParameter("@sInPlace", SqlDbType.NVarChar,50),
					new SqlParameter("@dOutDate", SqlDbType.DateTime),
					new SqlParameter("@sOutReason", SqlDbType.NVarChar,128),
					new SqlParameter("@sOutPlace", SqlDbType.NVarChar,50)};
            parameters[0].Value = model.sId;
            parameters[1].Value = model.sNumber;
            parameters[2].Value = model.sName;
            parameters[3].Value = model.sSex;
            parameters[4].Value = model.dBorn;
            parameters[5].Value = model.sMarry;
            parameters[6].Value = model.sIdentity;
            parameters[7].Value = model.sNation;
            parameters[8].Value = model.sEducation;
            parameters[9].Value = model.sWork;
            parameters[10].Value = model.sWorkPlace;
            parameters[11].Value = model.sPosition;
            parameters[12].Value = model.nAge;
            parameters[13].Value = model.sNative;
            parameters[14].Value = model.dJoin;
            parameters[15].Value = model.sMobile;
            parameters[16].Value = model.sAddress;
            parameters[17].Value = model.sPicture;
            parameters[18].Value = model.sCharge;
            parameters[19].Value = model.sComment;
            parameters[20].Value = model.iPicture;
            parameters[21].Value = model.dInDate;
            parameters[22].Value = model.sInReason;
            parameters[23].Value = model.sInPlace;
            parameters[24].Value = model.dOutDate;
            parameters[25].Value = model.sOutReason;
            parameters[26].Value = model.sOutPlace;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Gmis.Model.PMember model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update PMember set ");
            strSql.Append("sNumber=@sNumber,");
            strSql.Append("sName=@sName,");
            strSql.Append("sSex=@sSex,");
            strSql.Append("dBorn=@dBorn,");
            strSql.Append("sMarry=@sMarry,");
            strSql.Append("sIdentity=@sIdentity,");
            strSql.Append("sNation=@sNation,");
            strSql.Append("sEducation=@sEducation,");
            strSql.Append("sWork=@sWork,");
            strSql.Append("sWorkPlace=@sWorkPlace,");
            strSql.Append("sPosition=@sPosition,");
            strSql.Append("nAge=@nAge,");
            strSql.Append("sNative=@sNative,");
            strSql.Append("dJoin=@dJoin,");
            strSql.Append("sMobile=@sMobile,");
            strSql.Append("sAddress=@sAddress,");
            strSql.Append("sPicture=@sPicture,");
            strSql.Append("sCharge=@sCharge,");
            strSql.Append("sComment=@sComment,");
            strSql.Append("iPicture=@iPicture,");
            strSql.Append("dInDate=@dInDate,");
            strSql.Append("sInReason=@sInReason,");
            strSql.Append("sInPlace=@sInPlace,");
            strSql.Append("dOutDate=@dOutDate,");
            strSql.Append("sOutReason=@sOutReason,");
            strSql.Append("sOutPlace=@sOutPlace");
            strSql.Append(" where sId=@sId ");
            SqlParameter[] parameters = {
					new SqlParameter("@sNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@sName", SqlDbType.NVarChar,50),
					new SqlParameter("@sSex", SqlDbType.Char,4),
					new SqlParameter("@dBorn", SqlDbType.DateTime),
					new SqlParameter("@sMarry", SqlDbType.NVarChar,50),
					new SqlParameter("@sIdentity", SqlDbType.NVarChar,50),
					new SqlParameter("@sNation", SqlDbType.NVarChar,50),
					new SqlParameter("@sEducation", SqlDbType.NVarChar,50),
					new SqlParameter("@sWork", SqlDbType.NVarChar,50),
					new SqlParameter("@sWorkPlace", SqlDbType.NVarChar,50),
					new SqlParameter("@sPosition", SqlDbType.NVarChar,50),
					new SqlParameter("@nAge", SqlDbType.Int,4),
					new SqlParameter("@sNative", SqlDbType.NVarChar,200),
					new SqlParameter("@dJoin", SqlDbType.DateTime),
					new SqlParameter("@sMobile", SqlDbType.NVarChar,50),
					new SqlParameter("@sAddress", SqlDbType.NVarChar,100),
					new SqlParameter("@sPicture", SqlDbType.NVarChar,256),
					new SqlParameter("@sCharge", SqlDbType.NVarChar,50),
					new SqlParameter("@sComment", SqlDbType.NVarChar,300),
					new SqlParameter("@iPicture", SqlDbType.Image),
					new SqlParameter("@dInDate", SqlDbType.DateTime),
					new SqlParameter("@sInReason", SqlDbType.NVarChar,128),
					new SqlParameter("@sInPlace", SqlDbType.NVarChar,50),
					new SqlParameter("@dOutDate", SqlDbType.DateTime),
					new SqlParameter("@sOutReason", SqlDbType.NVarChar,128),
					new SqlParameter("@sOutPlace", SqlDbType.NVarChar,50),
					new SqlParameter("@sId", SqlDbType.VarChar,50)};
            parameters[0].Value = model.sNumber;
            parameters[1].Value = model.sName;
            parameters[2].Value = model.sSex;
            parameters[3].Value = model.dBorn;
            parameters[4].Value = model.sMarry;
            parameters[5].Value = model.sIdentity;
            parameters[6].Value = model.sNation;
            parameters[7].Value = model.sEducation;
            parameters[8].Value = model.sWork;
            parameters[9].Value = model.sWorkPlace;
            parameters[10].Value = model.sPosition;
            parameters[11].Value = model.nAge;
            parameters[12].Value = model.sNative;
            parameters[13].Value = model.dJoin;
            parameters[14].Value = model.sMobile;
            parameters[15].Value = model.sAddress;
            parameters[16].Value = model.sPicture;
            parameters[17].Value = model.sCharge;
            parameters[18].Value = model.sComment;
            parameters[19].Value = model.iPicture;
            parameters[20].Value = model.dInDate;
            parameters[21].Value = model.sInReason;
            parameters[22].Value = model.sInPlace;
            parameters[23].Value = model.dOutDate;
            parameters[24].Value = model.sOutReason;
            parameters[25].Value = model.sOutPlace;
            parameters[26].Value = model.sId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string sId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from PMember ");
            strSql.Append(" where sId=@sId ");
            SqlParameter[] parameters = {
					new SqlParameter("@sId", SqlDbType.VarChar,50)};
            parameters[0].Value = sId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string sIdlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from PMember ");
            strSql.Append(" where sId in (" + sIdlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Gmis.Model.PMember GetModel(string sId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 sId,sNumber,sName,sSex,dBorn,sMarry,sIdentity,sNation,sEducation,sWork,sWorkPlace,sPosition,nAge,sNative,dJoin,sMobile,sAddress,sPicture,sCharge,sComment,iPicture,dInDate,sInReason,sInPlace,dOutDate,sOutReason,sOutPlace from PMember ");
            strSql.Append(" where sId=@sId ");
            SqlParameter[] parameters = {
					new SqlParameter("@sId", SqlDbType.VarChar,50)};
            parameters[0].Value = sId;

            Gmis.Model.PMember model = new Gmis.Model.PMember();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["sId"] != null && ds.Tables[0].Rows[0]["sId"].ToString() != "")
                {
                    model.sId = ds.Tables[0].Rows[0]["sId"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sNumber"] != null && ds.Tables[0].Rows[0]["sNumber"].ToString() != "")
                {
                    model.sNumber = ds.Tables[0].Rows[0]["sNumber"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sName"] != null && ds.Tables[0].Rows[0]["sName"].ToString() != "")
                {
                    model.sName = ds.Tables[0].Rows[0]["sName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sSex"] != null && ds.Tables[0].Rows[0]["sSex"].ToString() != "")
                {
                    model.sSex = ds.Tables[0].Rows[0]["sSex"].ToString();
                }
                if (ds.Tables[0].Rows[0]["dBorn"] != null && ds.Tables[0].Rows[0]["dBorn"].ToString() != "")
                {
                    model.dBorn = DateTime.Parse(ds.Tables[0].Rows[0]["dBorn"].ToString());
                }
                if (ds.Tables[0].Rows[0]["sMarry"] != null && ds.Tables[0].Rows[0]["sMarry"].ToString() != "")
                {
                    model.sMarry = ds.Tables[0].Rows[0]["sMarry"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sIdentity"] != null && ds.Tables[0].Rows[0]["sIdentity"].ToString() != "")
                {
                    model.sIdentity = ds.Tables[0].Rows[0]["sIdentity"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sNation"] != null && ds.Tables[0].Rows[0]["sNation"].ToString() != "")
                {
                    model.sNation = ds.Tables[0].Rows[0]["sNation"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sEducation"] != null && ds.Tables[0].Rows[0]["sEducation"].ToString() != "")
                {
                    model.sEducation = ds.Tables[0].Rows[0]["sEducation"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sWork"] != null && ds.Tables[0].Rows[0]["sWork"].ToString() != "")
                {
                    model.sWork = ds.Tables[0].Rows[0]["sWork"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sWorkPlace"] != null && ds.Tables[0].Rows[0]["sWorkPlace"].ToString() != "")
                {
                    model.sWorkPlace = ds.Tables[0].Rows[0]["sWorkPlace"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sPosition"] != null && ds.Tables[0].Rows[0]["sPosition"].ToString() != "")
                {
                    model.sPosition = ds.Tables[0].Rows[0]["sPosition"].ToString();
                }
                if (ds.Tables[0].Rows[0]["nAge"] != null && ds.Tables[0].Rows[0]["nAge"].ToString() != "")
                {
                    model.nAge = int.Parse(ds.Tables[0].Rows[0]["nAge"].ToString());
                }
                if (ds.Tables[0].Rows[0]["sNative"] != null && ds.Tables[0].Rows[0]["sNative"].ToString() != "")
                {
                    model.sNative = ds.Tables[0].Rows[0]["sNative"].ToString();
                }
                if (ds.Tables[0].Rows[0]["dJoin"] != null && ds.Tables[0].Rows[0]["dJoin"].ToString() != "")
                {
                    model.dJoin = DateTime.Parse(ds.Tables[0].Rows[0]["dJoin"].ToString());
                }
                if (ds.Tables[0].Rows[0]["sMobile"] != null && ds.Tables[0].Rows[0]["sMobile"].ToString() != "")
                {
                    model.sMobile = ds.Tables[0].Rows[0]["sMobile"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sAddress"] != null && ds.Tables[0].Rows[0]["sAddress"].ToString() != "")
                {
                    model.sAddress = ds.Tables[0].Rows[0]["sAddress"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sPicture"] != null && ds.Tables[0].Rows[0]["sPicture"].ToString() != "")
                {
                    model.sPicture = ds.Tables[0].Rows[0]["sPicture"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sCharge"] != null && ds.Tables[0].Rows[0]["sCharge"].ToString() != "")
                {
                    model.sCharge = ds.Tables[0].Rows[0]["sCharge"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sComment"] != null && ds.Tables[0].Rows[0]["sComment"].ToString() != "")
                {
                    model.sComment = ds.Tables[0].Rows[0]["sComment"].ToString();
                }
                if (ds.Tables[0].Rows[0]["iPicture"] != null && ds.Tables[0].Rows[0]["iPicture"].ToString() != "")
                {
                    model.iPicture = (byte[])ds.Tables[0].Rows[0]["iPicture"];
                }
                if (ds.Tables[0].Rows[0]["dInDate"] != null && ds.Tables[0].Rows[0]["dInDate"].ToString() != "")
                {
                    model.dInDate = DateTime.Parse(ds.Tables[0].Rows[0]["dInDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["sInReason"] != null && ds.Tables[0].Rows[0]["sInReason"].ToString() != "")
                {
                    model.sInReason = ds.Tables[0].Rows[0]["sInReason"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sInPlace"] != null && ds.Tables[0].Rows[0]["sInPlace"].ToString() != "")
                {
                    model.sInPlace = ds.Tables[0].Rows[0]["sInPlace"].ToString();
                }
                if (ds.Tables[0].Rows[0]["dOutDate"] != null && ds.Tables[0].Rows[0]["dOutDate"].ToString() != "")
                {
                    model.dOutDate = DateTime.Parse(ds.Tables[0].Rows[0]["dOutDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["sOutReason"] != null && ds.Tables[0].Rows[0]["sOutReason"].ToString() != "")
                {
                    model.sOutReason = ds.Tables[0].Rows[0]["sOutReason"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sOutPlace"] != null && ds.Tables[0].Rows[0]["sOutPlace"].ToString() != "")
                {
                    model.sOutPlace = ds.Tables[0].Rows[0]["sOutPlace"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select sId,sNumber,sName,sSex,dBorn,sMarry,sIdentity,sNation,sEducation,sWork,sWorkPlace,sPosition,nAge,sNative,dJoin,sMobile,sAddress,sPicture,sCharge,sComment,iPicture,dInDate,sInReason,sInPlace,dOutDate,sOutReason,sOutPlace ");
            strSql.Append(" FROM PMember ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" sId,sNumber,sName,sSex,dBorn,sMarry,sIdentity,sNation,sEducation,sWork,sWorkPlace,sPosition,nAge,sNative,dJoin,sMobile,sAddress,sPicture,sCharge,sComment,iPicture,dInDate,sInReason,sInPlace,dOutDate,sOutReason,sOutPlace ");
            strSql.Append(" FROM PMember ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "PMember";
            parameters[1].Value = "sId";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method
    }
}

